// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

package repository

import (
	"github.com/kumose/kmopt/pkg/repository/v1manifest"
	"github.com/kumose/kmopt/pkg/utils"
)

// Repository represents a local components repository that mirrored the remote Repository(either filesystem or HTTP server).
type Repository interface {
	Mirror() Mirror
	WithOptions(opts Options) Repository
	UpdateComponents(specs []ComponentSpec) error
	ResolveComponentVersion(id, constraint string) (utils.Version, error)
	BinaryPath(installPath string, componentID string, ver string) (string, error)
	DownloadKmopt(targetDir string) error
	DownloadComponent(item *v1manifest.VersionItem, target string) error
	LocalLoadManifest(index *v1manifest.Index) (*v1manifest.Manifest, bool, error)
	LocalLoadComponentManifest(component *v1manifest.ComponentItem, filename string) (*v1manifest.Component, error)
	LocalComponentManifest(id string, withYanked bool) (com *v1manifest.Component, err error)
	LocalComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error)
	LocalComponentInstalled(component, version string) (bool, error)
	GetComponentManifest(id string, withYanked bool) (com *v1manifest.Component, err error)
	FetchIndexManifest() (index *v1manifest.Index, err error)
	FetchRootManifest() (root *v1manifest.Root, err error)
	PurgeTimestamp()
	UpdateComponentManifests() error
	LatestStableVersion(id string, withYanked bool) (utils.Version, *v1manifest.VersionItem, error)
	LatestNightlyVersion(id string) (utils.Version, *v1manifest.VersionItem, error)
	ComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error)
}

// Options represents options for a repository
type Options struct {
	GOOS              string
	GOARCH            string
	DisableDecompress bool
}
